package com.mareas.web.jsf.view;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.jsf.FacesContextUtils;

import com.mareas.web.model.Operacion;
import com.mareas.web.service.GenericService;

@Component("costosView")
@ManagedBean
@RequestScoped
public class CostosView implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1764376655399376673L;

	@Autowired
	private GenericService genericService;

	private Operacion operacionActual = null;

	public CostosView() {
		super();
	}

	public GenericService getGenericService() {
		return genericService;
	}

	public void setGenericService(GenericService genericService) {
		this.genericService = genericService;
	}

	public void store() {
		genericService.persist(operacionActual);
	}

	public Operacion getOperacionActual() {
		FacesContext facescontext = FacesContext.getCurrentInstance();
		if (this.operacionActual == null) {
			ApplicationBean applicationBean = (ApplicationBean) FacesContextUtils
					.getRequiredWebApplicationContext(facescontext).getBean(
							"applicationBean");
			this.operacionActual = applicationBean.getOperacionActual();
			

		}
		return this.operacionActual;
	}
	
	public void init() {
		operacionActual = null;
	}
	
}
